package com.example.springdataelastci.rabbit.consumer;

import com.example.springdataelastci.config.RabbitmqConfig;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;


/**
 * 接收消息
 *
 * @author heyangyang
 * @since 2023-11-18
 */
@Component
@Slf4j
public class DelayedQueueConsumer {

    @RabbitListener(queues = {RabbitmqConfig.DELAYED_QUEUE})
    public void receiveDelayedMessage(Message message, Channel channel) throws IOException {
        log.info("delayed 延迟队列开始接收消息了*******************************************");
        String msg = new String(message.getBody());
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), Boolean.FALSE);
        log.info("延迟队列接收的消息：{}, 时间:{}", msg, new Date());
    }

}
